package com.laicunba.service.jzh.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.laicunba.pojo.FinancingTargetBidDO;
import com.laicunba.service.jzh.JzhBidOrderService;
import com.laicunba.service.jzh.JzhSelloutService;

@Service
public class JzhSelloutServiceImpl implements JzhSelloutService {
	private static final Logger LOG = Logger.getLogger(JzhSelloutServiceImpl.class);
	@Autowired
	private JzhBidOrderService jzhBidOrderService;

	@Override
	public int onSellout(String financingTargetId) {
		List<String> orderIdList = jzhBidOrderService.findNewStatus(financingTargetId);
		if (orderIdList == null || orderIdList.isEmpty()) {
			return 0;
		}
		int len = 0;
		for (String orderId : orderIdList) {
			try {
				FinancingTargetBidDO financingTargetBidDO = jzhBidOrderService.makeLoans(orderId);
				len = financingTargetBidDO!=null ? len + 1 : len;
			} catch (Exception e) {
				LOG.error("放款失败", e);
			}
		}

		System.out.println(orderIdList);
		return len;
	}

}
